package com.ruihu.api.module.business.task.controller;

import com.ruihu.admin.common.anno.NoNeedLogin;
import com.ruihu.admin.common.anno.NoValidPrivilege;
import com.ruihu.admin.common.anno.OperateLog;
import com.ruihu.admin.common.domain.ResponseDTO;
import com.ruihu.admin.constant.SwaggerTagConst;
import com.ruihu.admin.module.business.stat.domain.dto.StatQueryDTO;
import com.ruihu.admin.module.business.stat.domain.vo.ChartLineVO;
import com.ruihu.admin.module.business.stat.domain.vo.DefectTop5VO;
import com.ruihu.admin.module.business.stat.domain.vo.ElectricCoreCountVO;
import com.ruihu.admin.module.business.stat.domain.vo.ElectricCoreTypeCountVO;
import com.ruihu.admin.module.business.stat.service.StatService;
import com.ruihu.admin.module.business.tasknode.domain.vo.DefectTypeVO;
import com.ruihu.admin.module.business.tasknode.service.DefectTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(tags = {SwaggerTagConst.BigScreen.STAT_API})
@OperateLog
public class BigScreenController {

    @Autowired
    private StatService statService;

    @Autowired
    private DefectTypeService defectTypeService;

    /**
     * 统计业务指标
     * @param queryDTO
     * @return
     */
    @ApiOperation(value="统计业务指标",notes = "@author Tony")
    @PostMapping("/api/stat/kpi")
    @NoValidPrivilege
    @NoNeedLogin
    public ResponseDTO<List<ElectricCoreCountVO>> queryKPI(@RequestBody StatQueryDTO queryDTO) {
        return this.statService.queryKPI();
    }


    /**
     * 查询拆解及不良数趋势图
     * @param queryDTO
     * @return
     */
    @ApiOperation(value="查询拆解及不良数趋势图",notes = "@author Tony")
    @PostMapping("/api/stat/disassembleAndEligible")
    @NoValidPrivilege
    @NoNeedLogin
    public ResponseDTO<ChartLineVO> queryDisassembleAndEligibleCount(@RequestBody StatQueryDTO queryDTO) {
        return this.statService.queryDisassembleAndEligibleCount(queryDTO);
    }

    /**
     * 电芯型号占比统计
     * @param queryDTO
     * @return
     */
    @ApiOperation(value="电芯型号占比统计",notes = "@author Tony")
    @PostMapping("/api/stat/countByElectricCoreType")
    @NoValidPrivilege
    @NoNeedLogin
    public ResponseDTO<ElectricCoreTypeCountVO> countByElectricCoreType(@RequestBody StatQueryDTO queryDTO) {
        return this.statService.countByElectricCoreType(queryDTO);
    }

    /**
     * 电芯缺陷类型Top5
     * @param queryDTO
     * @return
     */
    @ApiOperation(value="电芯缺陷类型Top5",notes = "@author Tony")
    @PostMapping("/api/stat/countTop5DefectType")
    @NoValidPrivilege
    @NoNeedLogin
    public ResponseDTO<DefectTop5VO> countTop5DefectType(@RequestBody StatQueryDTO queryDTO) {
        return this.statService.countTop5ByDefect(queryDTO);
    }

    @ApiOperation(value="电芯缺陷分类统计",notes = "@author Tony")
    @PostMapping("/api/stat/countElectricCoreByDefectType")
    @NoValidPrivilege
    @NoNeedLogin
    public ResponseDTO<ChartLineVO> countElectricCoreByDefectType(@RequestBody StatQueryDTO queryDTO) {
        return this.statService.queryElectricCoreDefectTypeCount(queryDTO);
    }

    @ApiOperation(value = "查询缺陷类型",notes = "@author Tony")
    @GetMapping("/api/defectType/query")
    @NoValidPrivilege
    @NoNeedLogin
    public ResponseDTO<List<DefectTypeVO>> queryDefectType() {
        return ResponseDTO.succData(defectTypeService.queryDefectType());
    }
}
